package ca.ets.osgi.hotelservice;

public class HotelInfo extends HotelAbs{
	
	private int availablePlace =0;
	private boolean availability = false;
	
	/**
	 * CONSTRUCTOR
	 */
	public HotelInfo(){super();}

	/**
	 * @return the availablePlace
	 */
	public int getAvailablePlace() {
		return availablePlace;
	}

	/**
	 * @param availablePlace the availablePlace to set
	 */
	public void setAvailablePlace(int availablePlace) {
		this.availablePlace = availablePlace;
	}

	/**
	 * @return the availability
	 */
	public boolean isAvailability() {
		return availability;
	}
	
	/**
	 * Set the Availability according to the actual number of place
	 */
	public void setAvailability(){
		if(this.availablePlace > 0){
			availability = true;
		}
		else{
			availablePlace =0;
			availability = false;
		}
	}
	
	/**
	 * Create an hotel reservation if there's a place available
	 * @return
	 */
	public HotelReservation getHotelReservation(String hotelArrivalDate,String hotelDepartureDate){
		HotelReservation hotel = null;
		if(isAvailability()){
			hotel = new HotelReservation();
			hotel.setHotelName(getHotelName());
			hotel.setHotelID(getHotelID());
			hotel.setPhone(getPhone());
			hotel.setAdresse(getAdresse());
			hotel.setDateStart(hotelArrivalDate);
			hotel.setDateEnd(hotelDepartureDate);
			this.availablePlace -= 1;
			setAvailability();
		}
		
		
		return hotel;
	}

	public String toString(){
		return this.getHotelName() + " , "+ this.getAdresse().getRue() + " " + this.getAdresse().getVille() + " " + this.getAdresse().getProvince() + " " + this.getAdresse().getCodePostal() +  " ,From " + this.getDateStart() + " To " + this.getDateEnd();
		
	}
}
